package framework

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
	"os"
)

type Conf struct {
	Mysql struct {
		Host     string	`yaml:"host"`
		Username string	`yaml:"username"`
		Password string	`yaml:"password"`
		Port     string	`yaml:"port"`
		Database string	`yaml:"database"`
		Charset  string	`yaml:"charset"`
	}
}

func (this *Conf) GetConf(path string) *Conf {
	if len(path) == 0 {
		pwd, _ := os.Getwd()
		path = pwd + "/conf/conf.yaml"
	}
	yamlFile, err := ioutil.ReadFile(path)
	if err != nil {
		log.Println(err)
		return nil
	}
	err = yaml.Unmarshal(yamlFile, this)
	if err != nil {
		log.Fatalf("%v", err)
	}
	return this
}
